package cn.wqb.bpp.common.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionUtils {

    /**
     * seconds 输入0或负数则Session永不超时
     */
    public static void setSession(HttpServletRequest request, String key, Object value, int seconds) {
        HttpSession session = request.getSession(true);//true表示找不到时new一个返回，false表示没有该会话时直接返回null
        session.setAttribute(key, value);
        session.setMaxInactiveInterval(seconds);
    }

    public static Object getSession(HttpServletRequest request, String key) {
        HttpSession session = request.getSession(true);//true表示找不到时new一个返回，false表示没有该会话时直接返回null
        return session.getAttribute(key);
    }

}
